#ifndef _H_HSTRING
#define _H_HSTRING

#include <wchar.h>
#include "hplatform.h"

#if __cplusplus
extern "C" {
#endif // #if __cplusplus

// if parameter str is utf8 string, return value is 0
int HPLATFORMCALL hstr_verify_utf8(const char* str);
wchar_t* HPLATFORMCALL hstr_g2w(const char* gbk_str);
char* HPLATFORMCALL hstr_g2u(const char* gbk_str);
char* HPLATFORMCALL hstr_g2g(const char* gbk_str);
wchar_t* HPLATFORMCALL hstr_u2w(const char* utf8_str);
char* HPLATFORMCALL hstr_u2g(const char* utf8_str);
char* HPLATFORMCALL hstr_u2u(const char* utf8_str);
char* HPLATFORMCALL hstr_w2g(const wchar_t* ucs2_str);
char* HPLATFORMCALL hstr_w2u(const wchar_t* ucs2_str);
wchar_t* HPLATFORMCALL hstr_w2w(const wchar_t* ucs2_str);
wchar_t* HPLATFORMCALL hstr_toggle_byteorder(const wchar_t* ucs2_str);
void HPLATFORMCALL hstr_free(void* buff);
#define HSTR_FREE(str)                  hstr_free((void*)str)

// split a string by specified divide chars, and post substring to handler, if handler returns 0,
// scan will go on, and will abort otherwise
// ex. hstr_split("a.b,c:.d;e", ".,:;", ...) will split orig string to a b c d e
typedef int (HPLATFORMCALL* substr_handler)(const char*, void*);
void HPLATFORMCALL hstr_split(const char* str_orig, const char* str_divide, substr_handler handler, void* param);

#if __cplusplus
}
#endif // #if __cplusplus

#endif // #ifndef _H_HSTRING

